#include <iostream>
#include <vector>
#include <map>

struct ThemeData {
    std::string theme_id;
    std::string parent_id;
    std::string name;
};

// 递归函数来构建子题材树
void buildChildThemeTree(const std::vector<ThemeData>& data, const std::string& parentId, std::map<std::string, std::vector<ThemeData>>& childThemeMap) {
    for (const ThemeData& theme : data) {
        if (theme.parent_id == parentId) {
            // 添加当前子题材到子题材列表
            childThemeMap[parentId].push_back(theme);
            // 递归构建子题材树
            buildChildThemeTree(data, theme.theme_id, childThemeMap);
        }
    }
}

// 打印子题材树
void printChildThemeTree(const std::map<std::string, std::vector<ThemeData>>& childThemeMap, const std::string& parentId, int level = 0) {
    for (int i = 0; i < level; ++i) {
        std::cout << "  "; // 缩进以表示层次关系
    }

    std::cout << "Parent Theme ID: " << parentId << std::endl;

    const auto& childThemes = childThemeMap.find(parentId);
    if (childThemes != childThemeMap.end()) {
        for (const ThemeData& childTheme : childThemes->second) {
            for (int i = 0; i < level + 1; ++i) {
                std::cout << "  "; // 根据层次关系缩进
            }
            std::cout << "Child Theme ID: " << childTheme.theme_id << ", Name: " << childTheme.name << std::endl;
            printChildThemeTree(childThemeMap, childTheme.theme_id, level + 1);
        }
    }
}

int main() {
    std::vector<ThemeData> themeData = {
        {"1", "0", "Parent Theme 1"},
        {"2", "0", "Parent Theme 2"},
        {"3", "1", "Child Theme 1.1"},
        {"4", "1", "Child Theme 1.2"},
        {"5", "2", "Child Theme 2.1"},
        {"6", "3", "Grandchild Theme 1.1.1"}
    };

    std::map<std::string, std::vector<ThemeData>> childThemeMap;

    buildChildThemeTree(themeData, "0", childThemeMap);

    // 打印子题材树
    printChildThemeTree(childThemeMap, "0");

    return 0;
}
